package com.util;

import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.core.convert.converter.Converter;

public class TimeStampControl implements Converter<String, Timestamp> {
	
	List<DateFormat> list=new ArrayList<DateFormat>();
	
	public TimeStampControl()
	{
		list.add(new SimpleDateFormat("yyyy-MM-dd"));
		list.add(new SimpleDateFormat("yyyy-MM-dd HH"));
		list.add(new SimpleDateFormat("yyyy-MM-dd HH:mm"));
		list.add(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
		list.add(new SimpleDateFormat("yyyy/MM/dd"));
		list.add(new SimpleDateFormat("yyyy/MM/dd HH"));
		list.add(new SimpleDateFormat("yyyy/MM/dd HH:mm"));
		list.add(new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"));
	}

	public Timestamp convert(String time) {
		// TODO Auto-generated method stub
		if(time==null||time.equals("")) {
            return null;
        }
		 Date tt=null;
		for(DateFormat format:list)
		{
			try {
				tt = format.parse(time);
				break;
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				continue;
			}
		}		
		 return new Timestamp(tt.getTime());
	}
	

	
	


}
